import {Http} from "../utils/http"

class User {
    user
    constructor() {
        this.user = wx.getStorageSync('user')
    }
    async getUserInfo() {
        if (!this.user) {
            return
        }
        const user = await Http.request({
            url: `/users/${this.user.id}`
        })
        this.user = user
        return user
    }
    async updateUserInfo(data) {
        if (!this.user) {
            return
        }
        const user = await Http.request({
            url: `/users/${this.user.id}`,
            data,
            method: 'PUT'
        })
        this.user = user
        wx.setStorageSync('user', user)
    }
    async getUserInformation() {
        if (!this.user) {
            return
        }
        return await Http.request({
            url: `/users/${this.user.id}/infomation`
        })
    }
}
export {
    User
}
